#ifndef __IS_CORE_RAYTRACE_TRIANGLEBUFFERINTERSECT__
#define __IS_CORE_RAYTRACE_TRIANGLEBUFFERINTERSECT__

#include <memory>

namespace IS
{
	class TriangleBuffer;

	class IS_CORE_API TriangleBufferIntersect
	{
	public:
		struct Hit
		{
			TriangleBuffer* tribuf;
			int faceIdx;	// face index
			float t;		// hitPoint = orig + t * dir
			float u, v, w;	// hitPoint = w * p0 + u * p1 + v * p2;
		};

		TriangleBufferIntersect();
		~TriangleBufferIntersect();

		/*! Assume tribuf.beginUpdate() is called before this method */
		void beginIntersect(LinkList<TriangleBuffer>& tribufs);

		/*! Returns the number of intersections occurs */
		size_t intersect(const Vec3f& orig, const Vec3f& dir, bool twosided);

		size_t getClosestHitIndex() const;

		const Hit & getHit(size_t i) const;

        Vec3f getHitPosition(size_t i) const;

        Vec3f getHitNormal(size_t i) const;

        Vec4f getHitColor(size_t i) const;

		/*! Assume tribuf.endUpdate() is called after this method */
		void endIntersect();

	private:
		class Impl;
		Impl* mImpl;
	};

}	// namespace IS

#endif	// __IS_CORE_RAYTRACE_TRIANGLEBUFFERINTERSECT__